package mainWindowSupport;

import java.awt.Dimension;

import javax.swing.BorderFactory;
import javax.swing.JScrollPane;
import javax.swing.JViewport;
import javax.swing.border.TitledBorder;


public class ShapeExplorer {
	
	JScrollPane explorerPane;
	ShapeTree shapeTree;
	
	public ShapeExplorer() {
		initPane();
	}
	
	private void initPane() {
		explorerPane = new JScrollPane();
		explorerPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
		explorerPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
		explorerPane.setPreferredSize(new Dimension(215,235));
		explorerPane.setMinimumSize(new Dimension(10,0));
		//explorerPane.
		// Use default border.
		TitledBorder titledBorder = BorderFactory.createTitledBorder("Shape Explorer");
		titledBorder.setTitleJustification(TitledBorder.CENTER);
		titledBorder.setTitlePosition(TitledBorder.BELOW_TOP);
		explorerPane.setBorder(titledBorder);

		shapeTree = new ShapeTree();
		JViewport treeView = new JViewport();
		treeView.setView(shapeTree.getTree());
		explorerPane.setViewport(treeView);
	}
	
	public JScrollPane getPane() {
		return explorerPane;
	}
	
	public ShapeTree getShapeTree()  {
		return shapeTree;
	}
	
	public void setView() {
		JViewport treeView = new JViewport();
		treeView.setView(shapeTree.getTree());
		explorerPane.setViewport(treeView);
		explorerPane.updateUI();
	}
	
	public void setShapeTree(ShapeTree tree) {
		shapeTree = tree;
		JViewport treeView = new JViewport();
		treeView.setView(shapeTree.getTree());
		explorerPane.setViewport(treeView);
		explorerPane.updateUI();
	}
}
